package cn.zh.npro.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import cn.zh.npro.Item.CrItem;
import cn.zh.npro.R;

/**
 * Created by WYN on 2018/3/13 0013.
 */

public class CrAdapter extends BaseAdapter {

    Context context;
    ArrayList<CrItem> arrayList;
    String txt;
    LayoutInflater inflater;
    public CrAdapter(Context context,ArrayList<CrItem> arrayList,String txt){
        this.context=context;
        this.arrayList=arrayList;
        this.txt=txt;
        inflater=LayoutInflater.from(context);
    }




    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (null==view){
            holder=new Holder();
            view=inflater.inflate(R.layout.cin_layout,null,false);
            holder.ntxt=view.findViewById(R.id.ntxt);
            holder.imag=view.findViewById(R.id.imag);
            view.setTag(holder);
        }else {
            holder= (Holder) view.getTag();
        }
        holder.ntxt.setText(arrayList.get(i).getClassName());
        if (txt.equals(arrayList.get(i).getClassName())){
            holder.imag.setVisibility(View.VISIBLE);
        }else {
            holder.imag.setVisibility(View.GONE);
        }


        return view;
    }




    public class Holder{
        TextView ntxt;
        ImageView imag;
    }



}
